package homework8;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Random;

public class work6 {
	public static void main(String[] args) throws IOException{
		FileInputStream fis=new FileInputStream("name.txt");
		BufferedReader br=new BufferedReader(new InputStreamReader(fis));
		ArrayList<String[]> arr=new ArrayList<String[]>();
		String s;
		while((s=br.readLine())!=null) {
			if(!s.isEmpty()) {
				String[] temp=s.split("-");
				arr.add(temp);
			}
		}
		fis=new FileInputStream("store3.txt");
		br=new BufferedReader(new InputStreamReader(fis));
		int count=Integer.valueOf(br.readLine());
		br.close();
		Random r=new Random();
		if(count==1) {
			while(true) {
				int abc=0;
				for(int i=0;i<arr.size();i++) {
					if(arr.get(i)[3].equals("1")) {
						abc++;
					}
				}
				if(abc==10) {
					count++;
					for(int i=0;i<arr.size();i++) {
						arr.get(i)[3]="0";
					}
					FileOutputStream fos=new FileOutputStream("name.txt");
					BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
					for(String[] i:arr) {
						String b=i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3];
						bw.write(b);
						bw.newLine();
					}
					bw.close();
					break;
				}
			    int a=r.nextInt(arr.size());
			    if(arr.get(a)[3].equals("1")) {
			    }
			    else {
			    	System.out.println(arr.get(a)[0]);
			    	arr.get(a)[3]="1";
			    	FileOutputStream fos=new FileOutputStream("name.txt");
					BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
					for(String[] i:arr) {
						String b=i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3];
						bw.write(b);
						bw.newLine();
					}
					bw.close();
					break;
			    }
			}
		}
		else {
			while(true) {
				int abc=0;
				for(int i=0;i<arr.size();i++) {
					if(arr.get(i)[3].equals("1")) {
						abc++;
					}
				}
				if(abc==10) {
					count++;
					for(int i=0;i<arr.size();i++) {
						arr.get(i)[3]="0";
					}
					FileOutputStream fos=new FileOutputStream("name.txt");
					BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
					for(String[] i:arr) {
						String b=i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3];
						bw.write(b);
						bw.newLine();
					}
					bw.close();
					
					break;
				}
			    int a=r.nextInt(arr.size());
			    if(arr.get(a)[3].equals("1")) {
			    }
			    else {
			    	System.out.println(arr.get(a)[0]);
			    	arr.get(a)[3]="1";
			    	FileOutputStream fos=new FileOutputStream("name.txt");
					BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
					for(String[] i:arr) {
						String b=i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3];
						bw.write(b);
						bw.newLine();
					}
					bw.close();
			    }
			}
		}
		FileOutputStream fos=new FileOutputStream("store3.txt");
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
		bw.write(String.valueOf(count));
		bw.close();
	}
}
